extends Node2D

@export var all_player_type_map_tres: AllPlayerTypeMap

var init_hand_pool_tres = CardManager.init_hand_pool_tres

@onready var text_edit = $GridContainer/TextEdit

func _ready():
	pass


func _on_tree_entered():
	Globals.player_type = AllPlayerTypeMap.PLAYER_TYPE.WARRIOR
	Globals.player_state = (
		all_player_type_map_tres.player_in_battle[Globals.player_type].create_instance()
	)
	$BattleMain.current_monster_group_id = "G1"


func _on_win_button_pressed():
	var monster_handler = $BattleMain.monster_handler
	for monster in monster_handler.get_children():
		monster.queue_free()


func _on_draw_button_pressed():
	Events.card_table_drad_one_card.emit()


func _on_draw_one_button_pressed():
	Events.card_table_drad_one_card_no_shuffle.emit()


func _on_add_card_button_pressed():
	var card_id = text_edit.text
	for i in init_hand_pool_tres.warrior_trophy_cards:
		if i.card_id == int(card_id):
			CardManager.draw_pool.add_card(i.duplicate())


func _on_discard_add_card_button_pressed():
	var card_id = text_edit.text
	for i in init_hand_pool_tres.warrior_trophy_cards:
		if i.card_id == int(card_id):
			CardManager.discard_pool.add_card(i.duplicate())


func _on_hand_add_card_button_pressed():
	var card_id = text_edit.text
	for i in init_hand_pool_tres.warrior_trophy_cards:
		if i.card_id == int(card_id):
			CardManager.draw_pool.add_card_front(i.duplicate())
			Events.card_table_drad_one_card_no_shuffle.emit()


func _on_point_button_pressed():
	CardManager.avail_point = CardManager.hand_point
	Events.card_table_point_update.emit()


func _on_anger_button_pressed():
	var num = text_edit.text
	Globals.player_state.anger = num


func _on_state_button_pressed():
	var num = text_edit.text
	var state_arr = num.split(":")
	if state_arr[0] == "weak":
		Globals.player_state.weak += (int(state_arr[1]));
		

	
